package com.example.lawyer.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import java.util.List;

/****
 * Grid通用适配器
 * @param <T>
 */

public class CurrentAdapters<T> extends BaseAdapter {

    public List<T> data;
    public int rid;
    public int brid;

    public CurrentAdapters(List<T> data, int rid, int brid) {
        this.data = data;
        this.rid = rid;
        this.brid = brid;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    ViewDataBinding viewDataBinding;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if(convertView==null)
        {
            viewDataBinding = DataBindingUtil.inflate(
                    LayoutInflater.from(parent.getContext()),
                    rid,
                    parent,
                    false

            );
        }else {
            viewDataBinding = DataBindingUtil.getBinding(convertView);
        }
        viewDataBinding.setVariable(brid,data.get(position));

        return viewDataBinding.getRoot();
    }
}
